﻿@using JxAudio.Front.Validators
@using JxAudio.TransVo
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<RePassword> Localizer
@inject HttpClient Http

<ValidateForm Model="RePassVo" OnValidSubmit="ChangePassword">
    <div class="row g-3">
        <div class="form-group col-12">
            <BootstrapPassword class="form-control" @bind-Value="RePassVo.OldPassword"/>
        </div>
        <div class="form-group col-12">
            <BootstrapPassword @bind-Value="RePassVo.NewPassword"/>
        </div>
        <div class="form-group col-12">
            <BootstrapPassword @bind-Value="RePassVo.ReNewPassword" ValidateRules="new List<IValidator>(){new RePasswordValidator()}"/>
        </div>
        <div class="modal-footer">
            <DialogCloseButton></DialogCloseButton>
            <Button Text="@Localizer["Ok"]" Icon="fa-solid fa-floppy-disk" ButtonType="ButtonType.Submit"></Button>
        </div>
    </div>
    
</ValidateForm>

@code {
    [CascadingParameter]
    private Func<Task>? OnCloseAsync { get; set; }
    
    public RePassVo RePassVo { get; set; } = new RePassVo();

    private async Task ChangePassword(EditContext arg)
    {
        var returnMessage = await Http.PostAsJsonAsync("/api/User/ResetPassword", RePassVo);
        if (await returnMessage.Content.ReadAsStringAsync() == "success")
        {
            if (OnCloseAsync != null)
            {
                await OnCloseAsync();
            }
        }
    }

}